package com.orange.adminapi.controller.activityReview;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.orange.core.pojo.BR;
import com.orange.core.pojo.PageReqDto;
import com.orange.core.pojo.R;
import com.orange.core.pojo.entity.activityReview.dto.ActivityReviewDTO;
import com.orange.core.pojo.entity.activityReview.vo.ActivityReviewVO;
import com.orange.core.pojo.req.activityReview.ActivityReviewPageReq;
import com.orange.core.service.activityReview.ActivityReviewService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>ClassName:ActivityRevewController</p>
 * <p>Description: 活动回顾controller</p>
 * <p>Author: lwm</p>
 * <p>Date: 2025/7/11 16:54</p>
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/activityReview")
public class ActivityRevewController {

    private final ActivityReviewService activityReviewService;

    /**
     * 获取活动回顾列表
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).ACTIVITY_REVIEW_LIST.permission.identifier)")
    @GetMapping("/list")
    public R<List<ActivityReviewVO>> list(){
        return R.ok(activityReviewService.activityReviewList());
    }

    /**
     * 活动回顾分页查询
     * @param pageReqDto
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).ACTIVITY_REVIEW_LIST.permission.identifier)")
    @PostMapping("/page")
    public R<Page<ActivityReviewVO>> page(@RequestBody PageReqDto<ActivityReviewPageReq> pageReqDto){
        Page<ActivityReviewVO> page = activityReviewService.page(pageReqDto);
        return R.ok(page);
    }

    /**
     * 新增活动回顾
     * @param activityReviewDTO
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).ACTIVITY_REVIEW_SAVE.permission.identifier)")
    @PostMapping
    public R<Boolean> save(@RequestBody @Validated ActivityReviewDTO activityReviewDTO){
        return BR.result(activityReviewService.save(activityReviewDTO));
    }


    /**
     * 修改活动回顾
     * @param activityReviewDTO
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).ACTIVITY_REVIEW_UPDATE.permission.identifier)")
    @PutMapping
    public R<Boolean> update(@RequestBody @Validated ActivityReviewDTO activityReviewDTO){
        return BR.result(activityReviewService.update(activityReviewDTO));
    }

    /**
     * 活动回顾批量删除
     * @param ids
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).ACTIVITY_REVIEW_DELETE.permission.identifier)")
    @DeleteMapping("/{ids}")
    public R<Boolean> remove(@PathVariable("ids") Integer[] ids){
        return BR.result(activityReviewService.deleteActivityReviewByIds(ids));
    }
}
